// Descriptive analysis micro (main text and supplemental)
// Low skill products by high skill workers
// Author: Erica Owen


version 14.2
use "mow_micro_rep.dta", clear


// Figure 2 (main text)

graph twoway (scatter reled schoolyrs if reled<4 & schoolyrs<25 & imf_adv==0) , ///
	 xline(12, lpattern(dash) lcolor(red)) ///
	yline(1, lpattern(dash) lcolor(red)) name(g1, replace) xtitle("Absolute skill (Years of schooling)")



// Figure A4
// scatterplot matrix  (appendix)
graph twoway scatter reled reled3 if imf_adv==0 & lforce==1 & reled<4, name(g1, replace) ///
	xtitle("Relative skill (%)") ytitle("Relative skill (ratio)")


	
// Define sample for descriptive stats
local z i.female age i.unemp i.bach  new_lngdppc lnnat lnpop i.year
local x1  c.reled
local x2 c.lnreal
local c if lforce==1 & imf_adv==0  

local y pctusdinc
reg `y' `x1' `z'   `c' & reled~=. & lnreal~=. [pw=weight] 
est sto t1_1


// Figures A1, A2, A3
// Income

graph bar pctusdinc if e(sample), over(ccode, label(angle(45) labsize(vsmall))) ytitle("Average relative income") name(bar, replace)

// Support
graph bar support if e(sample), over(ccode, label(angle(45) labsize(vsmall))) ytitle("Proportion support trade") name(bar, replace)


// Real mfg. exports graph


graph bar real_mfg if e(sample), over(ccode, label(angle(45) labsize(vsmall))) ytitle("Real mfg. exports") name(bar, replace)


  
  
 // Table A1 & A2
 // Summary tables

 

local z i.female age i.unemp i.bach  new_lngdppc lnnat lnpop i.year
local x1  c.reled
local x2 c.lnreal
local c if lforce==1 & imf_adv==0  

local y pctusdinc
reg `y' `x1' `z'   `c' & reled~=. & lnreal~=. [pw=weight] 


local vars pctusdinc inc_usd reled lnreal lnproj_mfg support tr_wg tr_jb fdi_gr ///
	female age unemp bach  new_lngdppc lnnat lnpop


estpost corr `vars' if e(sample) [pw=weight], matrix
esttab . using "correlations.rtf", not unstack compress b(2) label replace

 
local z i.female age i.unemp i.bach  new_lngdppc lnnat lnpop i.year
local x1  c.reled
local x2 c.lnreal
local c if lforce==1 & imf_adv==0  

local y pctusdinc
reg `y' `x1' `z'   `c' & reled~=. & lnreal~=. [pw=weight] 

local vars pctusdinc inc_usd reled lnreal lnproj_mfg support tr_wg tr_jb fdi_gr ///
	female age unemp bach  new_lngdppc lnnat lnpop
local address  Text/Tables

estpost sum `vars'  if e(sample)
esttab . using "sum.rtf",  cells("mean(fmt(2)) sd min max count(fmt(0))")  replace label noobs

  
  
 // Figure 1
 // Note this uses different data 
use "wdi_fig1_mow.dta", clear

sum blav if group==0, detail
local med=r(p50)
twoway (hist blav if group==0, percent width(1) fc(none) ) , ///
	xline(`med', lc(blue)) name(g0, replace) title("Low income", size(medsmall))  

sum blav if group==1, detail
local med=r(p50)
twoway (hist blav if group==1, percent width(1) fc(none) ) , ///
	xline(`med', lc(blue)) name(g1, replace) title("Middle income", size(medsmall))  

sum blav if group==2, detail
local med=r(p50)
twoway (hist blav if group==2, percent width(1) fc(none) ) , ///
	xline(`med', lc(blue)) name(g2, replace) title("High income", size(medsmall))
graph combine g0 g1 g2, cols(1) iscale(.7273) ysize(8) ///
                         imargins(tiny) xcommon name(g3, replace)
